package com.edu.exam.entity.curriculum.questionbank;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 简答题实体类
 * 对应数据库表：short_answer_question_base
 *
 * 根据B-02-03-07简答题管理子模块设计文档实现
 * 管理简答题的基础信息，包括题干内容、总分、难度等。
 * 支持主观题型的灵活配置和管理。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "short_answer_question_base")
@Comment("简答题主表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ShortAnswerQuestion {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 题目唯一标识符
     */
    @NotBlank(message = "题目ID不能为空")
    @Size(max = 50, message = "题目ID长度不能超过50个字符")
    @Column(name = "question_id", nullable = false, length = 50, unique = true)
    private String questionId;

    /**
     * 题目编号（格式：SA-YYYY-NNNN）
     */
    @NotBlank(message = "题目编号不能为空")
    @Size(max = 32, message = "题目编号长度不能超过32个字符")
    @Column(name = "question_code", nullable = false, length = 32, unique = true)
    private String questionCode;

    /**
     * 题目标题
     */
    @NotBlank(message = "题目标题不能为空")
    @Size(max = 200, message = "题目标题长度不能超过200个字符")
    @Column(name = "title", nullable = false, length = 200, unique = true)
    private String title;

    /**
     * 题目分类ID
     */
    @Column(name = "category_id")
    private Long categoryId;

    /**
     * 科目ID
     */
    @Column(name = "subject_id")
    private Long subjectId;

    /**
     * 题目内容
     */
    @NotBlank(message = "题目内容不能为空")
    @Column(name = "question_content", nullable = false, columnDefinition = "TEXT")
    private String questionContent;

    /**
     * 题目要求说明
     */
    @Column(name = "question_requirements", columnDefinition = "TEXT")
    private String questionRequirements;

    /**
     * 参考答案提示
     */
    @Column(name = "answer_hint", columnDefinition = "TEXT")
    private String answerHint;

    /**
     * 题目解析
     */
    @Column(name = "question_explanation", columnDefinition = "TEXT")
    private String questionExplanation;

    /**
     * 难度等级（1-5分）
     */
    @NotNull(message = "难度等级不能为空")
    @Column(name = "difficulty_level", nullable = false)
    private Integer difficultyLevel;

    /**
     * 题目总分
     */
    @NotNull(message = "题目总分不能为空")
    @Column(name = "total_score", nullable = false, precision = 8, scale = 2)
    private BigDecimal totalScore;

    /**
     * 建议答题时间（分钟）
     */
    @Column(name = "suggested_time_minutes")
    private Integer suggestedTimeMinutes;

    /**
     * 题目状态（DRAFT-草稿，PENDING-待审核，APPROVED-已通过，PUBLISHED-已发布，REJECTED-已拒绝，ARCHIVED-已归档）
     */
    @NotBlank(message = "题目状态不能为空")
    @Size(max = 20, message = "题目状态长度不能超过20个字符")
    @Column(name = "status", nullable = false, length = 20)
    private String status;

    /**
     * 题目版本号
     */
    @NotNull(message = "版本号不能为空")
    @Column(name = "version_number", nullable = false)
    private Integer versionNumber;

    /**
     * 答案要点数量
     */
    @NotNull(message = "评分要点数量不能为空")
    @Column(name = "scoring_point_count", nullable = false)
    private Integer scoringPointCount;

    /**
     * 参考答案数量
     */
    @NotNull(message = "参考答案数量不能为空")
    @Column(name = "reference_answer_count", nullable = false)
    private Integer referenceAnswerCount;

    /**
     * 评分标准ID
     */
    @Column(name = "grading_standard_id")
    private String gradingStandardId;

    /**
     * 字数限制配置ID
     */
    @Column(name = "word_limit_id")
    private String wordLimitId;

    /**
     * 评分模式（POINT_BASED-要点评分，OVERALL-整体评分，HYBRID-混合评分）
     */
    @Size(max = 30, message = "评分模式长度不能超过30个字符")
    @Column(name = "grading_mode", length = 30)
    private String gradingMode;

    /**
     * 是否允许部分得分
     */
    @NotNull(message = "部分得分设置不能为空")
    @Column(name = "allow_partial_score", nullable = false)
    private Boolean allowPartialScore;

    /**
     * 是否启用智能批阅
     */
    @NotNull(message = "智能批阅设置不能为空")
    @Column(name = "enable_smart_grading", nullable = false)
    private Boolean enableSmartGrading;

    /**
     * 智能批阅配置（JSON格式）
     */
    @Column(name = "smart_grading_config", columnDefinition = "TEXT")
    private String smartGradingConfig;

    /**
     * 知识点
     */
    @Column(name = "knowledge_points", columnDefinition = "TEXT")
    private String knowledgePoints;

    /**
     * 题目标签（JSON格式）
     */
    @Column(name = "tags", columnDefinition = "TEXT")
    private String tags;

    /**
     * 适用年级
     */
    @Size(max = 50, message = "适用年级长度不能超过50个字符")
    @Column(name = "grade_level", length = 50)
    private String gradeLevel;

    /**
     * 题目来源（ORIGINAL-原创，IMPORT-导入，CONTRIBUTION-贡献，AI_GENERATED-AI生成）
     */
    @Size(max = 30, message = "题目来源长度不能超过30个字符")
    @Column(name = "question_source", length = 30)
    private String questionSource;

    /**
     * 扩展属性（JSON格式）
     */
    @Column(name = "extended_properties", columnDefinition = "TEXT")
    private String extendedProperties;

    /**
     * 质量评分（0-100分）
     */
    @Column(name = "quality_score", precision = 5, scale = 2)
    private BigDecimal qualityScore;

    /**
     * 使用次数
     */
    @Column(name = "usage_count")
    private Integer usageCount;

    /**
     * 平均得分
     */
    @Column(name = "average_score", precision = 6, scale = 2)
    private BigDecimal averageScore;

    /**
     * 答题通过率
     */
    @Column(name = "pass_rate", precision = 5, scale = 4)
    private BigDecimal passRate;

    /**
     * 平均答题时间
     */
    @Column(name = "average_answer_time", precision = 8, scale = 2)
    private BigDecimal averageAnswerTime;

    /**
     * 创建者ID
     */
    @NotBlank(message = "创建者ID不能为空")
    @Size(max = 50, message = "创建者ID长度不能超过50个字符")
    @Column(name = "creator_id", nullable = false, length = 50)
    private String creatorId;

    /**
     * 创建者姓名
     */
    @Size(max = 50, message = "创建者姓名长度不能超过50个字符")
    @Column(name = "creator_name", length = 50)
    private String creatorName;

    /**
     * 审核者ID
     */
    @Size(max = 50, message = "审核者ID长度不能超过50个字符")
    @Column(name = "reviewer_id", length = 50)
    private String reviewerId;

    /**
     * 审核时间
     */
    @Column(name = "review_time")
    private LocalDateTime reviewTime;

    /**
     * 发布者ID
     */
    @Size(max = 50, message = "发布者ID长度不能超过50个字符")
    @Column(name = "publisher_id", length = 50)
    private String publisherId;

    /**
     * 发布时间
     */
    @Column(name = "publish_time")
    private LocalDateTime publishTime;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 软删除标识
     */
    @NotNull(message = "软删除标识不能为空")
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 更新人
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;
}